<?php
namespace Modules\User;

use Phalcon\DiInterface;

class Module implements \Phalcon\Mvc\ModuleDefinitionInterface {
    public function registerAutoloaders(DiInterface $di = null) {
        (new \Phalcon\Loader()) -> registerNamespaces([
			'Components' => SRC_PATH.DS.'components'.DS,

            __NAMESPACE__ . '\\Controllers' => __DIR__.DS.'controllers'.DS,
        ]) -> register();
    }

    public function registerServices(DiInterface $di) {
		$di -> set('dispatcher', function() {
			$dispatcher = new \Phalcon\Mvc\Dispatcher();
			$dispatcher -> setDefaultNamespace(__NAMESPACE__ . '\\Controllers');
			return $dispatcher;
		});

        $di -> set('view', function () {
			return (new \Phalcon\Mvc\View()) -> disable();
        });

		$di -> set('user', function() {
			return \Components\Account\Factory::load([
				'adapter' => 'User'
			]);
		}, false);

		$di -> set('trade', function() {
			return \Components\Trade\Factory::load([
				'adapter' => 'First'
			]);
		}, false);
  }
}